/**
 * API配置常量
 */

// API配置（支持环境变量覆盖）
export const API_CONFIG = {
  prefix: import.meta.env.VITE_API_PREFIX || '/api/v1',
  version: import.meta.env.VITE_API_VERSION || 'v1'
}

// API路径常量
export const API_PATHS = {
  // 认证相关
  AUTH: {
    LOGIN: '/auth/login',
    LOGOUT: '/auth/logout',
    USER_INFO: '/auth/userinfo'
  },
  
  // 用户管理
  USERS: {
    BASE: '/users',
    BY_ID: (id) => `/users/${id}`,
    CREATE: '/users',
    UPDATE: (id) => `/users/${id}`,
    DELETE: (id) => `/users/${id}`
  },
  
  // 供应商管理
  SUPPLIERS: {
    BASE: '/suppliers',
    BY_ID: (id) => `/suppliers/${id}`,
    CREATE: '/suppliers',
    UPDATE: (id) => `/suppliers/${id}`,
    DELETE: (id) => `/suppliers/${id}`
  },
  
  // 文件管理
  FILES: {
    UPLOAD: '/files/upload',
    UPLOAD_BATCH: '/files/upload/batch',
    BY_ID: (fileId) => `/files/${fileId}`,
    URL: (fileId) => `/files/${fileId}/url`,
    DELETE: (fileId) => `/files/${fileId}`
  },
  
  // 日志管理
  LOGS: {
    OPERATION: '/logs/operation',
    LOGIN: '/logs/login'
  }
}

/**
 * 构建完整的API URL
 * @param {string} path - API路径
 * @returns {string} 完整的API URL
 */
export function buildApiUrl(path) {
  if (path.startsWith('/')) {
    return API_CONFIG.prefix + path
  }
  return API_CONFIG.prefix + '/' + path
}

/**
 * 获取API配置
 * @returns {object} API配置对象
 */
export function getApiConfig() {
  return { ...API_CONFIG }
}